/**
 * 
 */
package com.gs.practice.thread;

/**
 * @author Sabuj Das | sabuj.das@gmail.com
 *
 */
public class TestObject {

	private volatile boolean doneT1 = false;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final TestObject o = new TestObject();
		Thread t1 = new Thread(new Runnable() {
			
			@Override
			public void run() {
				while(!o.doneT1)
					o.m1();
			}
		});
		t1.setName("T1");
		Thread t2 = new Thread(new Runnable() {
			
			@Override
			public void run() {
				while(!Thread.currentThread().isInterrupted())
					o.m2();
			}
		});
		t2.setName("T2");
		t1.start();
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		o.doneT1 = true;
		t2.start();
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		t2.interrupt();
	}

	
	public synchronized void m1(){
		System.out.println("m1");
	}
	
	public synchronized void m2(){
		System.out.println("m2");
	}
}
